package com.lfd.hashmap;

/**
 * @项目名： spring-emq
 * @包名： com.lfd.hashmap
 * @文件名: SequentialExecution
 * @创建者: liufudong@szyh-smart.com
 * @创建时间: 2024/10/13 15:59
 * @描述：
 */
public class SequentialExecution {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            try {
                Thread.sleep(3000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("Thread 1 is running");

        });

        Thread t2 = new Thread(() -> {
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("Thread 2 is running");
        });

        Thread t3 = new Thread(() -> {
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("Thread 3 is running");
        });
        Thread t4 = new Thread(() -> {
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("Thread 4 is running");
        });

        t1.start();
        try {
            t1.join(); // 等待 t1 完成
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        t2.start();
        try {
            t2.join(); // 等待 t2 完成
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        t3.start();
        try {
            t3.join(); // 等待 t3 完成
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t4.start();
        try {
            t4.join();
        }catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
